package com.cxhc.app.api;

import com.cxhc.app.api.vo.EnterpriseVo;
import com.cxhc.common.core.controller.BaseController;
import com.cxhc.common.core.domain.R;
import com.cxhc.common.core.page.TableDataInfo;
import com.cxhc.framework.web.service.SysLoginService;
import com.cxhc.system.domain.app.IntegralAfter;
import com.cxhc.system.domain.app.IntegralRecords;
import com.cxhc.system.domain.app.SysEnterprise;
import com.cxhc.system.service.app.IIntegralAfterService;
import com.cxhc.system.service.app.IIntegralRecordsService;
import com.google.common.collect.ImmutableMap;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 积分管理
 */
@RestController
@RequestMapping("/api/integral")
public class ApiIntegral extends BaseController {
    @Resource
    private IIntegralRecordsService integralRecordsService;

    @Resource
    private IIntegralAfterService integralAfterService;


    /**
     * 查询所有积分记录列表
     */
    @GetMapping("/list")
    public TableDataInfo list() {
        startPage();
        return getDataTable(integralRecordsService.selectIntegralRecordsList(null));
    }


    /**
     * 查询记录详情
     */
    @GetMapping("/info/{id}")
    public R<ImmutableMap<String, Object>> info(@PathVariable("id") Long id) {
        return R.ok(ImmutableMap.of(
                "recordsInfo", integralRecordsService.selectIntegralRecordsById(id),
                "integralAfterList", integralAfterService.selectIntegralAfterList(new IntegralAfter().setRecordId(id))));
    }

    /**
     * 提交记录
     */
    @PostMapping("/post")
    public R<String> post(@RequestBody @Valid IntegralRecords integralRecords) {
        int row = integralRecordsService.insertIntegralRecords(integralRecords);
        return row > 0 ? R.ok() : R.fail("提交失败,请联系管理员");
    }

    /**
     * 提交记录复议
     */
    @PostMapping("/postAfter")
    public R<String> postAfter(@RequestBody @Valid IntegralAfter integralAfter) {
        int row =integralAfterService.insertIntegralAfter(integralAfter);
        return row > 0 ? R.ok() : R.fail("提交失败,请联系管理员");
    }

}
